package ooDay03;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal o = new Dog("小黄",2,"黄");
        Dog g = (Dog) o;
        Swim s =(Swim) o;

        System.out.println(o instanceof Dog);
        System.out.println(o instanceof Swim);
        System.out.println(o instanceof Fish);
        if(o instanceof Fish){
            Fish f=(Fish) o;
        }

        Animal[] animals =new Animal[5];
        animals[0] = new Dog("小黑",2,"黑");
        animals[1] = new Dog("小黄",2,"黄");
        animals[2] = new Fish("小彩",1,"彩");
        animals[3] = new Fish("小金",1,"金");
        animals[4] = new Chick("小花",1,"花");

        for (int i=0;i<animals.length;i++){
            animals[i].drink();
            animals[i].eat();
            if(animals[i] instanceof Swim){
                //((Swim) animals[i]).swim();
                Swim sw=(Swim)animals[i];
                sw.swim();
            }
            if(animals[i] instanceof Dog){
                Dog dog = (Dog)animals[i];
                dog.lookHome();
            }
        }
    }
}
